//流程
Page({
  data: {
    student: "",
    teacher: false,
    id: "",
    options: ""
  },
  onLoad: function (options) {
    this.getData(options.id)
    if (options.teacher != undefined) {
    debugger
      this.setData({
        teacher: true,
        options
      })
    }
  },

  getData(id) {
    let that = this
    wx.request({
      url: 'http://localhost:8080/Examination_System_war/wxstudent/getMarkByStudentId',
      data: {
        studentId: id
      },
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        that.setData({
          student: result.data.studentCourseList,
          id
        })
      },
      fail: () => { },
      complete: () => { }
    });

  },

  goPage(e) {
    let that = this
    let course = e.currentTarget.dataset.operation
    wx.navigateTo({
      url: '/pages/addPoint/about?id=' + that.data.id + "&course=" + JSON.stringify(course),
    });
  },
  onShow: function () {
    // 获取当前小程序的页面栈
    let pages = getCurrentPages();
    // 数组中索引最大的页面--当前页面
    let currentPage = pages[pages.length - 1];
    // 打印出当前页面中的 options
    console.log(currentPage.options)
    this.getData(currentPage.options.id)
    if (currentPage.options.teacher != null && currentPage.options.teacher != undefined && currentPage.options.teacher != "") {
      this.setData({
        teacher: true
      })
    }
  },
  delete(e) {
    console.log(e)
    let id = e.currentTarget.dataset.operation.courseid
    let studentId = e.currentTarget.dataset.operation.studentid
    let that = this

    wx.showModal({
      title: '提示',
      content: '确认删除嘛？',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: 'http://localhost:8080/Examination_System_war/wxteacher/wxDeleteOne',
            data: {
              studentId,
              id
            },
            header: { 'content-type': 'application/x-www-form-urlencoded' },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: (result) => {
              wx.showToast({
                title: '删除成功',
                icon: 'none',
              });
              that.onShow();
            },
            fail: () => { },
            complete: () => { }
          });

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  appeal(e) {
    let student = e.currentTarget.dataset.operation;
    wx.navigateTo({
      url: '/pages/appeal/appeal?student=' + JSON.stringify(student),
    })
  }
});